package com.yugao.fintech.antelope.mps.controller;

import com.yugao.fintech.antelope.infra.InfraApi;
import com.yugao.fintech.antelope.infra.module.group.model.rqrs.DataGroupSaveReq;
import com.yugao.fintech.antelope.infra.module.group.model.rqrs.DataGroupUpdateReq;
import com.yugao.fintech.antelope.base.model.enums.DataGroupBizTypeEnum;
import com.yugao.fintech.antelope.mps.service.MsgPushTaskService;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

@Api(tags = "消息功能组")
@RestController
@RequestMapping("/msgPushTask/group")
public class PushTaskGroupController {
    @Autowired
    private MsgPushTaskService pushTaskService;

    @Autowired
    private InfraApi infraApi;

    @ApiOperation(value = "保存消息功能组")
    @PostMapping("/save")
    @RamResource(action = "msg:pushTaskGroup:save", name = "保存消息功能组", type = ActionType.WRITE)
    public Resp<?> saveDataGroup(@RequestBody DataGroupSaveReq req) {
        req.setBizType(DataGroupBizTypeEnum.MSG_PUSH_TASK.getType());
        return Resp.ok(infraApi.saveDataGroup(req));
    }

    @ApiOperation(value = "更新消息功能组")
    @PostMapping("/update")
    @RamResource(action = "msg:pushTaskGroup:update", name = "更新消息功能组", type = ActionType.WRITE)
    public Resp<?> updateDataGroup(@RequestBody DataGroupUpdateReq req) {
        return Resp.ok(infraApi.updateDataGroup(req));
    }

    @ApiOperation(value = "批量删除消息功能组")
    @DeleteMapping("/batchDelete")
    @RamResource(action = "msg:pushTaskGroup:delete", name = "删除消息功能组", type = ActionType.WRITE)
    public Resp<?> batchDeleteDataGroup(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(pushTaskService.batchDeleteGroup(ids));

    }

    @ApiOperation(value = "删除消息功能组")
    @DeleteMapping("/delete")
    @RamResource(action = "msg:pushTaskGroup:delete", name = "删除消息功能组", type = ActionType.WRITE)
    public Resp<?> deleteDataGroup(@RequestParam(value = "id") Long id) {
        return Resp.ok(pushTaskService.batchDeleteGroup(Collections.singletonList(id)));
    }
}
